package com.blog.frontend.pages.parts;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;

import com.blog.frontend.pages.EditArticlePage;
import com.blog.model.Article;

public class ArticleViewer extends Panel {
	private static final long serialVersionUID = 8735096120829237919L;
	
	public ArticleViewer(final String id, final Article a) {
		super(id);
		add(new Label("id", a.getId() != null ? a.getId().toString() : "new article"));
		add(new Label("title", a.getTitle()));
		
		if (a.isCompiled()) {
			final MultiLineLabel ml = new MultiLineLabel("content", a.getContent());
			ml.setEscapeModelStrings(false);
			add(ml);
		}
		else {
			final MultiLineLabel ml = new MultiLineLabel("content", "Notice: This article needs to be compiled. It may be out of date! <br/>" + a.getContent());
			ml.setEscapeModelStrings(false);
			add(ml);
		}
		add(new Link("editLink") {
			private static final long serialVersionUID = 6132370717123269194L;
			
			@Override
			public void onClick() {
				setResponsePage(new EditArticlePage(a));
			}
		});
	}
}